package com.deer.wms.instock.service.enter.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.deer.wms.ASN.manage.model.asn.AsnDetail;
import com.deer.wms.ASN.manage.model.asn.AsnMaster;
import com.deer.wms.base.system.model.Item.ItemInfo;
import com.deer.wms.base.system.model.OrderDetailBO;
import com.deer.wms.base.system.model.OrderToErpBO;
import com.deer.wms.base.system.service.ItemInfoService;
import com.deer.wms.instock.model.erpType.ErpType;
import com.deer.wms.instock.service.enter.AbstractEnterErp;
import com.deer.wms.project.root.util.DateUtils;
import com.deer.wms.system.manage.service.CodeRuleService;
import com.deer.wms.ware.task.service.PushErpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @Author: xu
 * @Date: 2022/06/20/11:19
 * @Description: null新增，10其他入库单
 */
@Component
public class Else  extends AbstractEnterErp {
    @Autowired
    private CodeRuleService codeRuleService;
    @Autowired
    private PushErpService pushErpService;
    @Autowired
    private ItemInfoService itemInfoService;


    public ErpType gainType() {
        return new ErpType(null, 10);
    }

    /**
     * 字段添加
     *  @param orderToErpBO
     * @param asnMaster
     * @param asnMap
     */
    @Override
    protected void add(OrderToErpBO orderToErpBO, AsnMaster asnMaster, Map<String, AsnDetail> asnMap) {
        //供应商id
        orderToErpBO.setSupplierId(asnMaster.getSupplierId());
        //红蓝字
        orderToErpBO.setRob(true);
        for (OrderDetailBO detail : orderToErpBO.getDetails()) {
            AsnDetail asnDetail = asnMap.get(detail.getDetailNo());
            ItemInfo itemInfo = itemInfoService.getOne(new QueryWrapper<ItemInfo>().eq("item_code", asnDetail.getItemCode()).last("limit 1"));
            //物料id
            detail.setItemId(itemInfo.getId());
            //删除没用的字段
            detail.setSourceBillDetailRowIndex(null);
            detail.setDetailNo(null);
        }
    }
    protected void pushErp(OrderToErpBO orderToErpBO){
        pushErpService.CreateIMBill(orderToErpBO);
    }
}
